home *** CD-ROM | disk | FTP | other *** search
- Path: lll-winken.llnl.gov!usenet
- From: Mark Spruiell <mes@llnl.gov>
- Newsgroups: comp.lang.c++
- Subject: SPARCompiler problem
- Date: Thu, 08 Feb 1996 15:28:05 -0800
- Organization: Lawrence Livermore National Laboratory
- Message-ID: <311A8705.41C6@llnl.gov>
- NNTP-Posting-Host: disaster.llnl.gov
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (X11; I; IRIX 5.2 IP22)
-
- I've encountered a discrepancy between two C++ compilers. I'm using
- both SPARCompiler C++ 4.0.1 on Solaris 2.4 and SGI C++ 3.2.1 on IRIX 5.2.
- The code below illustrates what I'm trying to do. Using an overloaded
- operator new(), I get unexpected results when using SPARCompiler, and
- the expected results with SGI C++.
-
- When this program is run on the Sun, the resulting output is
-
- ** C++ new
- A constructor
- A constructor
- A constructor
- ** My new
- A constructor
-
- I was expecting to see three constructor messages after "My new", which
- is what I get on the SGI.
-
- I've checked the Sun patch lists, but couldn't find anything that sounded
- relevant.
-
- Firstly, am I correct in assuming that there should be three constructor
- messages? Secondly, if I am correct, doesn't this seem like a bug in
- the SPARCompiler? Is there a patch to fix this problem?
-
- Thanks,
-
- Mark Spruiell
- Lawrence Livermore National Laboratory
- mes@llnl.gov
-
-
- #include <iostream.h>
- #include <new.h>
-
- class A
- {
- public:
- A() { cout << "A constructor" << endl; }
- };
-
- void* operator new(size_t size, int dummy)
- {
- return ::operator new(size);
- }
-
- int main(int, char**)
- {
- cout << "** C++ new" << endl;
- A* a1 = new A[3];
-
- cout << "** My new" << endl;
- A* a2 = new(0) A[3];
-
- return 0;
- }
-